import { defineStore } from "pinia";
import { store } from "@/store";
import { cityIdType } from "./types";
import { storageSession } from "@pureadmin/utils";

// 340200 为安徽芜湖市
const cityIdKey = "cityId";

export const globalDataStore = defineStore({
  id: "pure-globalData",
  state: (): cityIdType => ({
    cityId: storageSession().getItem<string>(cityIdKey) ?? "340200"
  }),
  getters: {
    getCityId() {
      return this.cityId;
    }
  },
  actions: {
    CHANGE_CITY_ID(cityId: string) {
      // console.log("CHANGE_CITY_ID cityId:", cityId);
      this.cityId = cityId;
    }
  }
});

export function globalDataStoreHook() {
  return globalDataStore(store);
}
